/**
 * 获得搜索参数
 * @param params
 * @returns {Object}
 */
function getSearchParams(params) {
    var searchParams = new Object();
    if (params != undefined) {
        searchParams = params;
    }
    $('.SearchForm').each(function() {
        var param = $(this).val().trim();
        var val = $("input:checkbox[name='sex']:selected").val();
        if (val == 1) {
            searchParams['sex'] = 1;
        } else if (val == 2) {
            searchParams['sex'] = 2;
        }
        if (param == undefined)
            param = '';
        searchParams[$(this).attr('name')] = param;
    });
    return searchParams;
}
//清空搜索条件
$("#Reset").click(function() {
    $('.SearchForm').val('');
    $("input:radio[name='sex']").removeAttr('checked');
});

/**
 * 页面自加载
 */
$(function() {

    var cellwidth = ($(".box-content.table-responsive").width() - 55) / 11;
    var psval = $('#datatable_dealinfo').attr('data-size');
    if (psval == undefined || psval == "") {
        psval = 10;
    }
    /**
     * easyui 生成表格数据
     */
    $('#datatable_dealinfo').datagrid({
        singleSelect: true, //允许选择多行
        striped: true,
        idField: 'h_id',
        remoteSort: false,
        collapsible: true,
        fit: false,
        url: 'admin/Show/getDealData', //数据源路径
        loadMsg: '请等待数据载入....',
        pagination: true,
        rownumbers: true,
        fitColumns: true,
        pageSize: psval,
        pageList: [psval, psval * 2, psval * 3, psval * 4, psval * 5],
        columns: [[{
            field: 'd_number',
            title: '系统订单号',
            align: 'center',
            width: cellwidth*1.2,
            sortable: true
        },{
            field: 'd_trade_no',
            title: '微信订单号',
            align: 'center',
            width: cellwidth*1.8,
            sortable: true
        },{
            field: 'whoname',
            title: '买赞者',
            align: 'center',
            width: cellwidth,
            sortable: true
        }, {
            field: 'receivename',
            title: '得赞人',
            align: 'center',
            width: cellwidth,
            sortable: true
        }, {
            field: 'd_money',
            title: '付款金额',
            align: 'center',
            width: cellwidth*0.5,
            sortable: true
        }, {
            field: 'd_zan',
            title: '所得赞数',
            align: 'center',
            width: cellwidth*0.5,
            sortable: true
        }, {
            field: 'd_time',
            title: '付款时间',
            align: 'center',
            width: cellwidth,
            sortable: true
        }, {
            field: 'd_status',
            title: '付款状态',
            align: 'center',
            width: cellwidth,
            sortable: true,
            formatter: function (value,row,index) {
                if(value===2){
                    return "<span style='color: green;'>付款成功</span>";
                }else{
                    return "<span style='color: red;'>付款失败</span>";
                }
            }
        }]],
        onBeforeLoad: function (param) {
            param = getSearchParams(param);
        },
    });

    $('#Search').click(function() {
        $('#datatable_dealinfo').datagrid('reload');
    });
    
});